package main.SQL.objects;

import main.MainApp;

import javax.swing.tree.DefaultMutableTreeNode;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SQLDocument extends DefaultMutableTreeNode {

    private int docId;
    private int statusId;
    private int catgId;
    private int parentDocId;
    private int projectId;
    private String docName;
    private String docNumber;
    private String docAuthor;
    private String dbName;

    //region Structure ids
    private int isImportFactage;
    private int epsId;
    private int titulId;
    private int objectId;
    private int smetId;
    //endregion


    //region Конструктора для нового рута
    public SQLDocument() {

        this.docId = 0;
        this.statusId = 0;
        this.catgId = 0;
        this.parentDocId = 0;
        this.docName = "Сметы Фактаж";
        this.docNumber = "";
        this.docAuthor = "";
        if (MainApp.curProject != null) {
            this.projectId = MainApp.curProject.getId();
            this.dbName = MainApp.curProject.getDbName();
        }
    }
    //endregion

    //region Конструктор для загрузки документов из Primavera
    public SQLDocument(ResultSet rs) throws SQLException {

        this.docId = rs.getInt("doc_id");
        this.statusId = rs.getInt("status_id");
        this.catgId = rs.getInt("catg_id");
        this.parentDocId = rs.getInt("parent_doc_id");
        this.docName = rs.getString("doc_name");
        this.docNumber = rs.getString("doc_number");
        this.docAuthor = rs.getString("doc_author");
        this.projectId = rs.getInt("proj_id");
        this.dbName = rs.getString("db_name");

        if (rs.getObject("import_factage") != null) this.isImportFactage = rs.getInt("import_factage");
        if (rs.getObject("eps_id") != null) this.epsId = rs.getInt("eps_id");
        if (rs.getObject("titul_id") != null) this.titulId = rs.getInt("titul_id");
        if (rs.getObject("object_id") != null) this.objectId = rs.getInt("object_id");
        if (rs.getObject("smet_id") != null) this.smetId = rs.getInt("smet_id");

    }
    //endregion

    @Override
    public String toString() {
        return docName;
    }

    //region Блок геттеров и сеттеров
    public int getDocId() {
        return docId;
    }

    public void setDocId(int docId) {
        this.docId = docId;
    }

    public int getStatusId() {
        return statusId;
    }

    public void setStatusId(int statusId) {
        this.statusId = statusId;
    }

    public int getCatgId() {
        return catgId;
    }

    public void setCatgId(int catgId) {
        this.catgId = catgId;
    }

    public int getParentDocId() {
        return parentDocId;
    }

    public void setParentDocId(int parentDocId) {
        this.parentDocId = parentDocId;
    }

    public int getProjectId() {
        return projectId;
    }

    public void setProjectId(int projectId) {
        this.projectId = projectId;
    }

    public String getDocNumber() {
        return docNumber;
    }

    public void setDocNumber(String docNumber) {
        this.docNumber = docNumber;
    }

    public String getDocAuthor() {
        return docAuthor;
    }

    public void setDocAuthor(String docAuthor) {
        this.docAuthor = docAuthor;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getDocName() {
        return docName;
    }

    public void setDocName(String docName) {
        this.docName = docName;
    }

    public int getIsImportFactage() {
        return isImportFactage;
    }

    public void setIsImportFactage(int isImportFactage) {
        this.isImportFactage = isImportFactage;
    }

    public int getEpsId() {
        return epsId;
    }

    public void setEpsId(int epsId) {
        this.epsId = epsId;
    }

    public int getTitulId() {
        return titulId;
    }

    public void setTitulId(int titulId) {
        this.titulId = titulId;
    }

    public int getObjectId() {
        return objectId;
    }

    public void setObjectId(int objectId) {
        this.objectId = objectId;
    }

    public int getSmetId() {
        return smetId;
    }

    public void setSmetId(int smetId) {
        this.smetId = smetId;
    }
    //endregion
}
